﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace ebc.componentbinder.tests
{
    [TestFixture]
    public class test_WireUpPins
    {
        [Test]
        public void Connect_matching_pins_and_let_a_message_run_from_client_to_service()
        {
            var c = new C();
            var op = new OutputPin(c, typeof (C).GetEvent("OnX"));

            var s = new S();
            var ip = new InputPin(s, typeof (S).GetMethod("ProcessX"));

            ComponentBinder.WireUpPins(new OutputInputPinPair {Out = op, In = ip}, null);

            c.Run("abc");
            Assert.AreEqual("abc", s.Received);
        }


        [Test]
        public void Connect_with_listener()
        {
            var c = new C();
            var op = new OutputPin(c, typeof(C).GetEvent("OnX"));

            var s = new S();
            var ip = new InputPin(s, typeof(S).GetMethod("ProcessX"));

            string receivedByListener="";
            ComponentBinder.WireUpPins(new OutputInputPinPair { Out = op, In = ip },
                                       x => receivedByListener = (string)x);

            c.Run("abc");

            Assert.AreEqual("abc", receivedByListener);
        }
    }
}
